<template>
  <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="150px">
        <div class="tl-form-line-title" style="margin-top:16px">
          基本信息
        </div>
        <el-row>
          <el-col :span="12">
            <el-form-item label="项目来源" prop="projectsource">
              <el-select v-model="model.projectsource" @change="changeSource" filterable clearable :disabled="true">
                <el-option v-for="item in codeModel.projectSourceList" :key="item.code" :label="item.name" :value="item.code" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="leadOrChanceLabel" prop="chanceclue">
              <el-input v-model="model.chanceclue" :disabled="true" class="tl-ref-selector" :class="{ disabled: true }">
                <el-button slot="append" type="primary" icon="el-icon-search" :disabled="true" @click="openChanceclueDialog"></el-button>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="项目名称" prop="projectname" :rules="rules.rulesForInfo">
              <el-input v-model="model.projectname" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="项目级别" prop="projectlevel" :rules="rules.rulesForInfo">
              <el-row type="flex">
                <el-select v-model="model.projectlevel" filterable clearable disabled class="levelSelect">
                  <el-option v-for="item in codeModel.projectlevelList" :key="item.code" :label="item.name" :value="item.code" />
                </el-select>
                <el-button type="primary" icon="el-icon-edit-outline" @click="openChangeLevelDialog" :disabled="true" class="levelButton"></el-button>
              </el-row>
            </el-form-item>
          </el-col>
          <el-col :span="1">
            <el-popover trigger="hover" placement="left">
              <el-table :data="gridData" :span-method="objectSpanMethod" :border="true">
                <el-table-column width="120" property="projectlevel" label="项目级别" align="center"></el-table-column>
                <el-table-column min-width="400" property="projectleveldetail" label="项目级别定义" header-align="center"></el-table-column>
                <el-table-column width="100" property="sponsor" label="Sponsor" header-align="center"></el-table-column>
                <el-table-column width="120" property="owner" label="Owner" header-align="center"></el-table-column>
                <el-table-column width="120" property="manager" label="PM" header-align="center"></el-table-column>
              </el-table>
              <div style="font-size: 15px">注：以上是项目级别的实施原则，如果与上述原则产生异议，可以在立项决策会上申请调级。</div>
              <i slot="reference" class="el-icon-question" style="font-size: 20px;margin-left: 4px;margin-top: 3px;color: #909399" />
            </el-popover>
          </el-col>
        </el-row>
        <!-- <el-row>
          <el-col :span="12">
            <el-form-item label="项目编号" prop="projectcode">
              <el-input v-model="model.projectcode" :disabled="true" placeholder="系统自动生成"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目经理" prop="projectmanager" :rules="rules.rulesForInfo">
              <el-input v-model="model.projectmanager" :disabled="true"></el-input>
            </el-form-item>
          </el-col>
        </el-row> -->
        <el-row>
          <el-col :span="12">
            <el-form-item label="客户名称" prop="clientname" :rules="rules.rulesForInfo">
              <el-input v-model="model.clientname" :disabled="true"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户部门" prop="clientdept" :rules="rules.rulesForInfo">
              <el-input v-model="model.clientdept" :disabled="true"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="可参与金额" prop="participatemoney" :rules="model.projectsource === '1' ? [] : rules.rulesForInfo"> <el-input-number v-model="model.participatemoney" :disabled="true" controls-position="right" :step="1" :min="0" :precision="2" class="unitInputNumber"></el-input-number><span class="unitSpan">万元</span> </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="采购模式" prop="purchasepattern" :rules="model.projectsource === '1' ? [] : rules.rulesForInfo">
              <el-select v-model="model.purchasepattern" filterable clearable @change="changepurchasepattern" :disabled="true">
                <el-option v-for="item in codeModel.MpmPurchasePatternList" :key="item.code" :label="item.name" :value="item.code" :disabled="true" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="计划开始日期" prop="planstartdate" :rules="rules.rulesForInfo">
              <el-date-picker v-model="model.planstartdate" type="date" placeholder="例：2022-01-01" value-format="yyyy-MM-dd" @change="planStart" :disabled="true"> </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="计划结束日期" prop="planenddate" :rules="rules.rulesForInfo">
              <el-date-picker v-model="model.planenddate" type="date" placeholder="例：2022-01-01" value-format="yyyy-MM-dd" @change="planEnd" :disabled="true"> </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="需求上报时间" prop="demandbegindate">
              <el-date-picker v-model="model.demandbegindate" type="date" placeholder="例：2022-01-01" value-format="yyyy-MM-dd" :disabled="true"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="需求截止时间" prop="demandenddate">
              <el-date-picker v-model="model.demandenddate" type="date" placeholder="例：2022-01-01" value-format="yyyy-MM-dd" :disabled="true"></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="创建部门" prop="deptname" :rules="rules.rulesForInfo">
              <tl-ref-dept v-model="model.deptname" :initDisplayData.sync="model.deptname" dataType="code" nameType="fullname" @confirm="onSelectDept" :singleSelect="true" :externalQueryParam="{ qry_enabled: 1 }" :disabled="true"> </tl-ref-dept>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
            <el-form-item label="项目周期" prop="bidcycle">
              <el-input v-model="model.bidcycle" class="unitInput" placeholder="系统自动计算" :disabled="true"
                ><template #append
                  >天</template
                ></el-input
              >
            </el-form-item>
          </el-col> -->
          <el-col :span="12">
            <el-form-item label="区域" prop="deptname1">
              <el-cascader style="width:100%" :options="provinceCityList" :props="{ checkStrictly: true }" v-model="deptname" filterable @change="changeDeptname" clearable disabled> </el-cascader>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="Sponsor" prop="sponsorcode" :rules="rules.rulesForInfo">
              <tl-ref-user v-model="model.sponsorcode" :initDisplayData.sync="model.sponsor" dataType="code" :singleSelect="true" :disabled="true"> </tl-ref-user>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="Owner" prop="ownercode" :rules="rules.rulesForInfo">
              <tl-ref-user v-model="model.ownercode" :initDisplayData.sync="model.owner" dataType="code" :singleSelect="true" :disabled="true"> </tl-ref-user>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="决策组人员" prop="decisionusername">
              <el-input v-model="model.decisionusername" :disabled="true" class="tl-ref-selector">
                <el-button slot="append" type="primary" icon="el-icon-search" @click="openMpmProjectResourcePoolDialog" v-if="false" :disabled="true"></el-button>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="historyLevel && model.dispprojectlevel !== historyLevel">
          <el-col :span="12">
            <el-form-item label="原项目级别">
              <el-input v-model="historyLevel" class="tl-ref-selector" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="model.changelevelreason">
          <el-col :span="24">
            <el-form-item label="项目级别调整原因" prop="changelevelreason" :rules="rules.rulesForInfo">
              <el-input v-model="model.changelevelreason" type="textarea" :rows="4" maxlength="1000" show-word-limit disabled> </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="model.bidbegindate">
          <el-col :span="24">
            <el-form-item label="招标批次" prop="bidinfo">
              <el-input v-model="model.bidinfo" :disabled="true" placeholder="请填写批次全称，如国网**省电力公司**年第**次**招标"> </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="model.bidbegindate">
          <el-col :span="12">
            <el-form-item label="挂网日期" prop="bidbegindate">
              <el-date-picker v-model="model.bidbegindate" type="date" placeholder="例：2022-01-01" value-format="yyyy-MM-dd" :disabled="true"> </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开标日期" prop="bidenddate">
              <el-date-picker v-model="model.bidenddate" type="date" placeholder="例：2022-01-01" value-format="yyyy-MM-dd" :disabled="true"> </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- <tl-project-bid-date ref="projectBidDate" :projectid="model.id" :planstartdate="model.planstartdate" :planenddate="model.planenddate" :forview="true"></tl-project-bid-date> -->
        <div v-if="model.approvaltype === '1'">
          <div class="tl-form-line-title">
            会议决议记录
          </div>
          <meet-list-comp ref="meetlist" :disableEditSubmit="true" :sourcetype="'meetResolution'" :projectid="model.id"></meet-list-comp>
        </div>
        <el-row v-if="model.productlist && model.productlist.length > 0 && Array.isArray(model.productlist)">
          <div class="tl-form-line-title">
            内部产品信息
          </div>
          <el-row v-for="(item, index) in model.productlist" :key="index">
            <el-col :span="8">
              <el-form-item label="产品线/事业部" label-width="100px" style="margin-left: 50px">
                <el-select v-model="item.productlinecode" :disabled="true">
                  <el-option v-for="item in codeModel.productlineList" :key="item.code" :label="item.name" :value="item.code" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="产品类别">
                <el-select v-model="item.productcode" :disabled="true" v-if="model.projectsource === '1'">
                  <el-option v-for="item in codeModel.productcatalog1List" :key="item.code" :label="item.name" :value="item.code" />
                </el-select>
                <el-select v-model="item.productcode" :disabled="true" v-if="model.projectsource === '2'">
                  <el-option v-for="item in codeModel.productcatalog2List" :key="item.code" :label="item.name" :value="item.code" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="金额"> <el-input-number v-model="item.fund" class="unitInputNumber" controls-position="right" :step="1" :min="0" :precision="2" :disabled="true"></el-input-number><span class="unitSpan">万元</span> </el-form-item>
            </el-col>
          </el-row>
        </el-row>
        <el-row v-if="model.productoutlist && model.productoutlist.length > 0 && Array.isArray(model.productoutlist)">
          <div class="tl-form-line-title">
            外部产品信息
          </div>
          <el-row v-for="(item, index) in model.productoutlist" :key="index">
            <el-col :span="12">
              <el-form-item label="产品类别">
                <el-input v-model="item.productname" disabled class="tl-ref-selector"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="金额"> <el-input-number v-model="item.fund" controls-position="right" :step="1" :min="0" :precision="2" class="unitInputNumber" :disabled="true"></el-input-number><span class="unitSpan">万元</span> </el-form-item>
            </el-col>
          </el-row>
        </el-row>
        <div class="tl-form-line-title">
          项目描述
        </div>
        <el-row>
          <el-col :span="24">
            <el-form-item label="项目背景" prop="background">
              <el-input v-model="model.background" type="textarea" :rows="4" maxlength="1000" show-word-limit :disabled="true"> </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="项目目标" prop="target">
              <el-input v-model="model.target" type="textarea" :rows="4" maxlength="1000" show-word-limit :disabled="true"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="总体策划" prop="summary">
              <el-input v-model="model.summary" type="textarea" :rows="4" maxlength="1000" show-word-limit :disabled="true"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-collapse value="approval" :disabled="false">
          <el-collapse-item title="审批历史" name="approval">
            <div>
              <el-table v-show="listMode" class="tl-table" ref="mainTable" v-loading="loading" :data="datas" height="240px" @sort-change="doSortChange" row-key="id" border fit>
                <el-table-column type="index" label="序号" width="55px" align="center"> </el-table-column>
                <el-table-column prop="dispnodeid" label="流程节点" :show-overflow-tooltip="true" width="150px"> </el-table-column>
                <el-table-column prop="dispapprovaluserid" label="审批人" width="150px" align="center"> </el-table-column>
                <el-table-column prop="dispstate" label="状态" width="150px" align="center"> </el-table-column>
                <el-table-column prop="startdate" label="开始时间" width="160px" sortable="custom" sort-by="startdate" align="center"></el-table-column>
                <el-table-column prop="approvaldate" label="审批时间" width="160px" sortable="custom" sort-by="approvaldate" align="center"></el-table-column>
                <el-table-column prop="approvalcosttime" label="实际用时" width="160px" sortable="custom" sort-by="approvalcosttime" align="left"></el-table-column>
                <el-table-column prop="approvalopinion" label="审批意见" :show-overflow-tooltip="true" width="300px"> </el-table-column>
              </el-table>
              <!-- 列表分页 -->
              <el-row v-show="listMode" class="pagebar" ref="pager">
                <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
              </el-row>
            </div>
          </el-collapse-item>
        </el-collapse>
        <el-collapse value="approval" :disabled="false" v-if="changeapprovallist">
          <el-collapse-item title="项目信息变更审批历史" name="approval">
            <div>
              <el-table v-show="listMode" class="tl-table" ref="mainTable" v-loading="loading" :data="changedatas" height="240px" @sort-change="doSortChange" row-key="id" border fit>
                <el-table-column type="index" label="序号" width="55px" align="center"> </el-table-column>
                <el-table-column prop="dispnodeid" label="流程节点" :show-overflow-tooltip="true" width="150px"> </el-table-column>
                <el-table-column prop="dispapprovaluserid" label="审批人" width="150px" align="center"> </el-table-column>
                <el-table-column prop="dispstate" label="状态" width="150px" align="center"> </el-table-column>
                <el-table-column prop="startdate" label="开始时间" width="160px" sortable="custom" sort-by="startdate" align="center"></el-table-column>
                <el-table-column prop="approvaldate" label="审批时间" width="160px" sortable="custom" sort-by="approvaldate" align="center"></el-table-column>
                <el-table-column prop="approvalcosttime" label="实际用时" width="160px" sortable="custom" sort-by="approvalcosttime" align="left"></el-table-column>
                <el-table-column prop="approvalopinion" label="审批意见" :show-overflow-tooltip="true" width="300px"> </el-table-column>
              </el-table>
              <!-- 列表分页 -->
              <el-row v-show="listMode" class="pagebar" ref="pager">
                <el-pagination @size-change="doChangeSize2" @current-change="doChangeIndex2" :current-page="changeInfo.pageInfo.currentPage" :page-sizes="changeInfo.pageInfo.pageSizes" :total="changeInfo.pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
              </el-row>
            </div>
          </el-collapse-item>
        </el-collapse>
        <el-collapse value="approval" :disabled="false" v-if="circulateapprovallist">
          <el-collapse-item title="传阅反馈审批历史" name="approval">
            <div>
              <el-table v-show="circulateInfo.listMode" class="tl-table" ref="mainTable" v-loading="circulateInfo.loading" :data="circulateInfo.datas" height="240px" @sort-change="doSortChange" row-key="id" border fit>
                <el-table-column type="index" label="序号" width="55px" align="center"> </el-table-column>
                <el-table-column prop="dispnodeid" label="流程节点" :show-overflow-tooltip="true" width="150px"> </el-table-column>
                <el-table-column prop="dispapprovaluserid" label="审批人" width="150px" align="center"> </el-table-column>
                <el-table-column prop="dispstate" label="状态" width="150px" align="center"> </el-table-column>
                <el-table-column prop="startdate" label="开始时间" width="160px" sortable="custom" sort-by="startdate" align="center"></el-table-column>
                <el-table-column prop="approvaldate" label="审批时间" width="160px" sortable="custom" sort-by="approvaldate" align="center"></el-table-column>
                <el-table-column prop="approvalcosttime" label="实际用时" width="160px" sortable="custom" sort-by="approvalcosttime" align="left"></el-table-column>
                <el-table-column prop="approvalopinion" label="审批意见" :show-overflow-tooltip="true" width="300px"> </el-table-column>
              </el-table>
              <!-- 列表分页 -->
              <el-row v-show="circulateInfo.listMode" class="pagebar" ref="pager">
                <el-pagination @size-change="doChangeSize3" @current-change="doChangeIndex3" :current-page="circulateInfo.pageInfo.currentPage" :page-sizes="circulateInfo.pageInfo.pageSizes" :total="circulateInfo.pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
              </el-row>
            </div>
          </el-collapse-item>
        </el-collapse>
      <!-- <el-tab-pane label="客户信息" name="projectcustomerinfo">
        <div style="margin-top: 1px; margin-left: -20px" class="mancomment">
          <el-row v-for="item in model.customerlist" :key="item.clientcode + item.clientname">
            <el-col :span="12">
              <el-form-item label="客户名称">
                <el-input v-model="item.clientname" disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="客户部门">
                <el-input v-model="item.clientdept" disabled></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="需求上报时间" prop="demandbegindate" :rules="model.purchasepattern && (model.purchasepattern === '3' || model.purchasepattern === '9') ? [] : rules.validateRequire">
                <el-date-picker v-model="model.demandbegindate" type="date" placeholder="例：2021-01-01" value-format="yyyy-MM-dd" :disabled="true"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="需求截止时间" prop="demandenddate" :rules="model.purchasepattern && (model.purchasepattern === '3' || model.purchasepattern === '9') ? [] : rules.validateRequire">
                <el-date-picker v-model="model.demandenddate" type="date" placeholder="例：2021-01-01" value-format="yyyy-MM-dd" :disabled="true"></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="客户需求分析" prop="clientdemand">
                <el-input v-model="model.clientdemand" type="textarea" :rows="6" maxlength="800" show-word-limit :disabled="true"> </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <div class="tl-form-line-title" style="margin-top:6px">
            客户决策
          </div>
          <tl-project-customer-decision ref="projectCustomer" :projectid="model.id"></tl-project-customer-decision>
        </div>
      </el-tab-pane> -->
      <!-- <el-tab-pane label="竞争对手" name="projectcompetitorinfo">
        <div style="margin-top: 1px; margin-left: -50px" class="mancomment">
          <el-row>
            <el-col :span="24">
              <el-form-item label="主要竞争对手" prop="competitor">
                <el-input v-model="model.competitor" type="textarea" :rows="8" maxlength="800" show-word-limit :disabled="true"> </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="SWOT分析" prop="swot">
                <el-input v-model="model.swot" type="textarea" :rows="8" maxlength="800" show-word-limit :disabled="true"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-tab-pane> -->
    <!-- <el-button type="primary" style="position:absolute;right:570px;top:10px;" @click.native="openChangeManager()" v-if="isCFOForThisProject">项目经理变更</el-button> -->
    <tl-attachment sourceType="MpmProject" :sourceId="model.id" :editable="false" v-if="model.projectmanagercode === user.code" style="position:absolute;right:550px;top:10px;"></tl-attachment>
    <tl-attachment sourceType="MpmProject" :sourceId="model.id" :editable="false" v-else style="position:absolute;right:470px;top:10px;"></tl-attachment>
    <el-button type="primary" style="position:absolute;right:470px;top:10px;" v-if="model.projectmanagercode === user.code" @click.native="openProjectEdit()">编辑</el-button>
    <el-button type="primary" style="position:absolute;right:370px;top:10px;" v-if="model.projectmanagercode === user.code" @click.native="openProjectChange()">立项变更</el-button>
    <el-button type="primary" style="position:absolute;right:370px;top:10px;" v-else @click.native="openProjectChange()">立项变更</el-button>
    <el-button type="primary" style="position:absolute;right:270px;top:10px;" v-if="model.projectmanagercode === user.code" @click.native="openCirculateDialog">传阅反馈</el-button>
    <el-button type="primary" style="position:absolute;right:270px;top:10px;" v-else @click.native="openCirculateDialog">传阅反馈</el-button>
    <el-button type="primary" style="position:absolute;right:140px;top:10px;" v-if="model.projectmanagercode === user.code" @click.native="$refs.history.visible = true">立项审批历史</el-button>
    <el-button type="primary" style="position:absolute;right:140px;top:10px;" v-else @click.native="$refs.history.visible = true">立项审批历史</el-button>
    <el-button type="primary" style="position:absolute;right:10px;top:10px;" v-if="model.projectmanagercode === user.code" @click.native="$refs.changehistory.visible = true" :disabled="disableChangeHistory">变更审批历史</el-button>
    <el-button type="primary" style="position:absolute;right:10px;top:10px;" v-else @click.native="$refs.changehistory.visible = true" :disabled="disableChangeHistory">变更审批历史</el-button>
    <TlMpmProjectCirculateEdit ref="projectCirculated"></TlMpmProjectCirculateEdit>
    <tlmpm-project-change ref="projectChanger" :mpmprojectid="model.id"></tlmpm-project-change>
    <tlmpm-project-edit ref="projectEdit" :mpmprojectid="model.id" @refreshdata="refreshData"></tlmpm-project-edit>
    <mpm-project-circle ref="projectCricle"></mpm-project-circle>
    <!-- <tl-approval-history ref="history" sourceType="MpmProject" :sourceId="model.id" />
    <tl-approval-history ref="Changehistory" sourceType="MpmProjectChange" :sourceId="changehistorymodelid" /> -->
    <approval-history ref="history" :history-myflow-id="'history-myflow-1'" sourceType="MpmProject" :sourceId="model.id ? model.id : 0"></approval-history>
    <approval-history ref="changehistory" :history-myflow-id="'history-myflow-2'" sourceType="MpmProjectChange" :sourceId="changehistorymodelid ? changehistorymodelid : 0"></approval-history>
  </el-form>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
import { mixin_edit } from '@tapui/mixins/mixin_edit'
/** 子组件 */
import { validateNull } from '@tapui/utils/validate'
import tlmpmProjectChange from '@/views/mpm/mpmProjectChange/edit'
import tlmpmProjectEdit from '@/views/mpm/mpmProjectChange/editPart'
import mpmProjectCircle from '@/views/mpm/mpmProjectCirculated/circulateManage'
import TlMpmProjectCirculateEdit from '../mpmProjectCirculated/edit'
import meetListComp from '../../../components/meet/meetListComp'
// import tlProjectBidDate from '@/views/mpm/mpmProjectBidDate/edit'
import approvalHistory from '@/views/mpm/mpmProject/approvalHistory'
import tlProjectCustomerDecision from '@/views/mpm/mpmProjectCustomerDecision/editForTrack'

/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
/** VUE配置 */
export default {
  mixins: [mixin_list, mixin_edit],
  components: { tlmpmProjectChange, mpmProjectCircle, TlMpmProjectCirculateEdit, approvalHistory, tlProjectCustomerDecision, meetListComp, tlmpmProjectEdit },
  data() {
    return {
      bidrequired: true,
      moduleTitle: '项目立项',
      urlPrefix: '/mpm/projectpolymerization/',
      url: {
        // 额外的url
        queryOrgByDeptId: '/mpm/project/queryOrgByDeptId',
        list: '/cbo/approvalNodeIns/list',
        checkCirculatedRecord: '/mpm/project/checkCirculatedRecord',
        queryCirculatedIdByProjectCode: '/mpm/projectCirculated/queryCirculatedIdByProjectCode',
        changeList: '/mpm/project/changeList',
        isCFO: '/mpm/project/isCFO',
        getProjectChangeManager: '/mpm/projectChangeManager/getProjectChangeManager',
        getProvinceCityList: '/mpm/projectpolymerization/getProvinceCityList',
        ifReviewed: '/mpm/projectReview/ifReviewed'
      },
      sorterInfo: {
        // 排序参数
        sidx: 'createon',
        sord: 'desc'
      },
      midChangePoint: true,
      datas: [],
      changedatas: [],
      changeapprovallist: false,
      circulateapprovallist: false,
      approvalcosttime: '',
      days: '',
      shengyvhour: '',
      hours: '',
      shengyvminute: '',
      minutes: '',
      projectcode: '',
      disableChangeHistory: false,
      changehistorymodelid: 0,
      pageInfo: {
        // 分页参数
        currentPage: 1, // 当前页面
        pageSize: 10, // 每页记录数
        pageSizes: ['10', '50', '100'],
        totalCount: 0 // 总数
      },
      circulateInfo: {
        loading: false,
        datas: [],
        approvalcosttime: '',
        days: '',
        shengyvhour: '',
        hours: '',
        shengyvminute: '',
        minutes: '',
        listMode: true,
        circulatedId: 0,
        pageInfo: {
          // 分页参数
          currentPage: 1, // 当前页面
          pageSize: 10, // 每页记录数
          pageSizes: ['10', '50', '100'],
          totalCount: 0 // 总数
        }
      },
      changeInfo: {
        pageInfo: {
          // 分页参数
          currentPage: 1, // 当前页面
          pageSize: 10, // 每页记录数
          pageSizes: ['10', '50', '100'],
          totalCount: 0 // 总数
        }
      },
      loading: false,
      visible: false,
      listMode: true,
      tabName: 'projectbasicinfo',
      // 项目级别默认编码值，根据选择的机会点确定
      tempprojectlevel: '',
      // 项目级别默认显示值，根据选择的机会点确定
      tempdispprojectlevel: '',
      // 项目等级，例：网级、省级等
      maxLevel: -1,
      isCFOForThisProject: false,
      deptname: [],
      provinceCityList: [],
      gridData: [
        {
          projectlevel: 'A级',
          projectleveldetail: '1）战规中承接业务设计的项目。',
          sponsor: '系统部部长/其他相关方',
          owner: '经营管理部部长',
          manager: '省总'
        },
        {
          projectlevel: 'A级',
          projectleveldetail: '2）具有战略性、突破性，差距大、额度超大的项目。',
          sponsor: '系统部部长/其他相关方',
          owner: '经营管理部部长',
          manager: '省总'
        },
        {
          projectlevel: 'B级',
          projectleveldetail: '1）省招需要调动的公司资源较少，相对成熟的项目。',
          sponsor: '系统部部长/其他相关方',
          owner: '省总',
          manager: '副总/CTO'
        },
        {
          projectlevel: 'B级',
          projectleveldetail: '2）市、县级可参与金额300万元及以上。',
          sponsor: '系统部部长/其他相关方',
          owner: '省总',
          manager: '副总/CTO'
        },
        {
          projectlevel: 'C级',
          projectleveldetail: '基层项目。',
          sponsor: '省总',
          owner: '副总/CTO',
          manager: '行销/区域经理'
        }
      ],
      // 根据对应关系合并相同项目等级，3表示共三列等级相同
      spanArr: [2, 0, 2, 0, 1],
      dispLevelArr: ['A', 'B', 'C', 'D']
    }
  },
  props: {
    projectId: {
      type: Number,
      default: 0
    },
    projectinfo: {},
    // 来自于哪个index组件
    fromIndexType: {
      type: String,
      default: ''
    }
  },
  computed: {
    leadOrChanceLabel() {
      if (this.model.projectsource && this.codeModel.projectSourceList) {
        return this.codeModel.projectSourceList.find((item) => item.code === this.model.projectsource).name
      } else {
        return '线索/机会点'
      }
    },
    historyLevel() {
      if (this.model.levelhistory) {
        return JSON.parse(this.model.levelhistory.replace(/\//g, '')).oldprojectlevel
      } else {
        return ''
      }
    }
  },
  methods: {
    changepurchasepattern(value) {
      if (value === '9' || value === '3') {
        this.bidrequired = false
      } else {
        this.bidrequired = true
      }
    },
    planStart(e) {
      var a = new Date(this.model.planstartdate)
      var b = new Date()
    },
    planEnd(e) {
      if (this.model.planstartdate === '' || typeof this.model.planstartdate === 'undefined') {
        this.$tap.alert('请先选择计划开始日期！', 'warning')
        this.$set(this.model, 'planenddate', '')
        this.$set(this.model, 'bidcycle', '')
        return
      }
      var c = new Date(this.model.planenddate).getTime()
      var d = new Date(this.model.planstartdate).getTime()
      if (c < d) {
        this.$tap.alert('开始日期不得大于结束日期。', 'warning')
        this.$set(this.model, 'planenddate', '')
        this.$set(this.model, 'bidcycle', '')
        return
      }
      var a = c - d
      var days = Math.ceil(a / (1000 * 3600 * 24)) + 1
      this.$set(this.model, 'bidcycle', days)
      // 计划结束日期存储为选择日期的的23：59：59
      let date = new Date(c)
      let timeDate = ''
      let Y = date.getFullYear() + '-'
      let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
      let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' '
      let h = 23 + ':'
      let m = 59 + ':'
      let s = 59
      timeDate = Y + M + D + h + m + s
      this.$set(this.model, 'planenddate', timeDate)
    },
    async openProjectChange() {
      let temp = await this.queryOtherChangeInfo(2)
      if (!temp) {
        this.$tap.alert('存在编辑中开立或审核中单据，请在编辑提交后进行立项变更操作')
        return
      }
      getAction(this.url.ifReviewed, { projectcode: this.projectinfo.projectcode })
        .then((res) => {
          if (res.success) {
            if (res.result) {
              this.$tap.alert('该项目已提交复盘审批，无法新增单据!')
            } else {
              var param = {
                qry_projectcode: this.projectinfo.projectcode,
                qry_newadd: 1,
                qry_state: '0,1,2',
                qry_changetype: 1
              }
              getAction('/mpm/projectChange/list', param).then((res) => {
                // 如果当前用户是项目经理才可编辑，如果来自于归档模块则能查看
                if (this.model.projectmanagercode !== this.$store.getters.user.code || this.fromIndexType === 'file') {
                  if (res.result.dataList.length !== 0) {
                    this.openViewDialog('projectChanger', res.result.dataList[0].id)
                  } else {
                    this.$tap.alert('该项目暂时没有变更记录', 'warning')
                  }
                } else {
                  if (res.result.dataList.length === 0) {
                    this.openAddDialog('projectChanger', this.model)
                  } else {
                    this.openEditDialog('projectChanger', res.result.dataList[0].id)
                  }
                }
              })
            }
          } else {
            this.$tap.alert(res.message, 'warning')
          }
        })
        .catch((err) => {
          this.$tap.alert(err, 'warninig')
        })
    },
    async queryOtherChangeInfo(changetype) {
      var param = {
        qry_projectcode: this.projectinfo.projectcode,
        qry_newadd: 1,
        qry_state: '0,1,2',
        qry_changetype: changetype
      }
      return await getAction('/mpm/projectChange/list', param).then((res) => {
        if (res.success) {
          if (res.result.dataList.length !== 0) {
            return false
          } else {
            return true
          }
        } else {
          return false
        }
      })
    },
    async openProjectEdit() {
      let temp = await this.queryOtherChangeInfo(1)
      if (!temp) {
        this.$tap.alert('存在立项变更开立或审核中单据，请在立项变更结束后进行编辑操作')
        return
      }
      getAction(this.url.ifReviewed, { projectcode: this.projectinfo.projectcode })
        .then((res) => {
          if (res.success) {
            if (res.result) {
              this.$tap.alert('该项目已提交复盘审批，无法新增单据!')
            } else {
              var param = {
                qry_projectcode: this.projectinfo.projectcode,
                qry_newadd: 1,
                qry_state: '0,1,2',
                qry_changetype: 2
              }
              getAction('/mpm/projectChange/list', param).then((res) => {
                // 如果当前用户是项目经理才可编辑，如果来自于归档模块则能查看
                if (this.model.projectmanagercode !== this.$store.getters.user.code || this.fromIndexType === 'file') {
                  if (res.result.dataList.length !== 0) {
                    this.openViewDialog('projectEdit', res.result.dataList[0].id)
                  } else {
                    this.$tap.alert('该项目暂时没有变更记录', 'warning')
                  }
                } else {
                  if (res.result.dataList.length === 0) {
                    this.openAddDialog('projectEdit', this.model)
                  } else {
                    this.openEditDialog('projectEdit', res.result.dataList[0].id)
                  }
                }
              })
            }
          } else {
            this.$tap.alert(res.message, 'warning')
          }
        })
        .catch((err) => {
          this.$tap.alert(err, 'warninig')
        })
    },
    /** 打开新增对话框实现 */
    openAddDialog(editForm, rowData) {
      if (!this.beforeOpenAddDialog(editForm, rowData)) {
        return
      }
      this.$refs[editForm].projectmodel = rowData
      this.$refs[editForm].isAdd = true
      this.$refs[editForm].visible = true
      this.$refs[editForm].disableEditSubmit = false
      this.$nextTick(() => {
        this.afterOpenAddDialog(editForm, rowData)
      })
    },
    /** 加载审批历史列表数据 */
    loadData(paramMap) {
      if (validateNull(paramMap) === false && Object.keys(paramMap).indexOf('currentPage') > -1) {
        this.pageInfo.currentPage = paramMap['currentPage']
      }
      getAction('/mpm/projectChange/list', { qry_projectcode: this.projectinfo.projectcode, qry_state: '1,2,9', sidx: 'createon', sord: 'desc', pageSize: 10, currentPage: 1, qry_changetype: 1 }).then((res) => {
        if (res.success) {
          if (res.result.dataList.length > 0) {
            this.changeapprovallist = true
            // 查询变更审批历史
            let changeparams = {
              currentPage: this.pageInfo.currentPage,
              pageSize: this.pageInfo.pageSize,
              qry_sourceid: res.result.dataList[0].id,
              qry_sourcetype: 'MpmProjectChange',
              sidx: 'approvaldate',
              sord: 'desc'
            }
            getAction(this.url.list, changeparams).then((t) => {
              if (t.success) {
                this.addCostTime(t)
                this.changedatas = t.result.dataList
                this.changeInfo.pageInfo.totalCount = t.result.totalCount
              }
            })
          } else {
            this.changeapprovallist = false
          }
        }
      })
      // 查询条件
      // var params = this.getQueryParams()
      let params = {
        currentPage: this.pageInfo.currentPage,
        pageSize: this.pageInfo.pageSize,
        qry_sourceid: this.projectId,
        qry_sourcetype: 'MpmProject',
        sidx: 'approvaldate',
        sord: 'desc'
      }
      // 清除垃圾数据
      this.approvalcosttime = ''
      this.days = ''
      this.shengyvhour = ''
      this.hours = ''
      this.shengyvminute = ''
      this.minutes = ''
      // 数据查询
      this.loading = true
      getAction(this.url.list, params)
        .then((res) => {
          if (res.success) {
            // 增加展示审批用时
            this.addCostTime(res)
            this.datas = res.result.dataList
            this.pageInfo.totalCount = res.result.totalCount
          } else {
            this.$tap.alert(res.message, 'warning')
          }
          this.loading = false
        })
        .catch((err) => {
          this.loading = false
        })
      this.queryCirculateHistory()
    },
    addCostTime(res) {
      for (let i = 0; i < res.result.dataList.length; i++) {
        if (res.result.dataList[i].approvaldate !== null && res.result.dataList[i].startdate !== null) {
          let a = new Date(res.result.dataList[i].approvaldate).getTime() - new Date(res.result.dataList[i].startdate).getTime()
          // 1天的毫秒数
          let daymiseconds = 1000 * 60 * 60 * 24
          // 1小时的毫秒数
          let hourmiseconds = 60 * 60 * 1000
          // 1分钟的毫秒数
          let minutesmiseconds = 60 * 1000
          if (a > daymiseconds) {
            this.days = Math.floor(a / daymiseconds)
            this.shengyvhour = a - this.days * daymiseconds
            this.hours = Math.floor(this.shengyvhour / hourmiseconds)
            this.shengyvminute = this.shengyvhour - this.hours * hourmiseconds
            this.minutes = Math.floor(this.shengyvminute / minutesmiseconds)
            this.approvalcosttime = this.days + '天' + this.hours + '小时' + this.minutes + '分钟'
            this.$set(res.result.dataList[i], 'approvalcosttime', this.approvalcosttime)
          } else if (a > hourmiseconds) {
            this.hours = Math.floor(a / hourmiseconds)
            this.shengyvminute = a - this.hours * hourmiseconds
            this.minutes = Math.floor(this.shengyvminute / minutesmiseconds)
            this.approvalcosttime = '0天' + this.hours + '小时' + this.minutes + '分钟'
            this.$set(res.result.dataList[i], 'approvalcosttime', this.approvalcosttime)
          } else {
            this.minutes = Math.floor(a / minutesmiseconds)
            this.approvalcosttime = '0天0小时' + this.minutes + '分钟'
            this.$set(res.result.dataList[i], 'approvalcosttime', this.approvalcosttime)
          }
        }
      }
    },
    /** 查询传阅反馈审批历史 **/
    queryCirculateHistory() {
      // 先查询sourceid
      getAction(this.url.queryCirculatedIdByProjectCode, { projectcode: this.projectinfo.projectcode }).then((res) => {
        if (res.success) {
          // 若没有传阅反馈审批历史则直接返回
          if (!res.result.id) {
            this.circulateapprovallist = false
            return
          }
          let params = {
            currentPage: this.circulateInfo.pageInfo.currentPage,
            pageSize: this.circulateInfo.pageInfo.pageSize,
            qry_sourceid: res.result.id,
            qry_sourcetype: 'MpmProjectCirculated',
            sidx: 'approvaldate',
            sord: 'desc'
          }
          // 清除垃圾数据
          this.circulateInfo.approvalcosttime = ''
          this.circulateInfo.days = ''
          this.circulateInfo.shengyvhour = ''
          this.circulateInfo.hours = ''
          this.circulateInfo.shengyvminute = ''
          this.circulateInfo.minutes = ''
          // 数据查询
          this.circulateInfo.loading = true
          getAction(this.url.list, params)
            .then((res) => {
              if (res.success) {
                this.circulateapprovallist = res.result.dataList.length > 0
                // 增加展示审批用时
                this.addCostTime(res)
                this.circulateInfo.datas = res.result.dataList
                this.circulateInfo.pageInfo.totalCount = res.result.totalCount
              } else {
                this.$tap.alert(res.message, 'warning')
              }
              this.circulateInfo.loading = false
            })
            .catch((err) => {
              this.circulateInfo.loading = false
            })
        } else {
          this.$tap.alert(res.message, 'warning')
        }
      })
    },
    // 选择项目所属部门
    onSelectDept(selectedDepts) {
      const selectedDept = selectedDepts[0]
      const { id, code, fullname } = selectedDept
      this.$set(this.model, 'deptcode', code)
      this.$set(this.model, 'deptname', fullname)
      const param = {
        deptId: id
      }
      getAction(this.url.queryOrgByDeptId, param).then((res) => {
        if (res.success) {
          const { code: orgcode, name: orgname } = res.result
          this.$set(this.model, 'orgcode', orgcode)
          this.$set(this.model, 'orgname', orgname)
        } else {
          this.$tap.alert('已选部门关联公司信息错误，请联系系统管理员')
        }
      })
    },
    /** 页面打开时执行 - zhanglongfei 2019.10.18 */
    open() {
      this.model = {}
      this.$nextTick(() => {
        this.getFieldsCustomSetting('projectpolymerization', 'el-form')
        this.$refs.form.clearValidate()
        if (this.isAdd === true) {
          this.title = '添加' + this.moduleTitle
          // 需要添加重复判断
          if (this.$store.getters.param.isAvoidRepeat === true) {
            this.queryBillUid()
          }
          if (this.isQueryInitData === true) {
            // 后台进行数据初始化
            this.queryInitData().then((_) => {
              this.assignDefaultValue()
              this.loaded()
            })
          } else {
            // 前台进行数据初始化
            this.$set(this.model, 'enabled', 1)
            this.$set(this.model, 'sortcode', 0)
            this.assignDefaultValue()
            this.loaded()
          }
        } else if (this.disableEditSubmit === false) {
          this.title = '编辑' + this.moduleTitle
          this.queryData(this.id).then((_) => {
            this.loaded()
          })
        } else {
          this.title = '查看' + this.moduleTitle
          this.queryData(this.id).then((_) => {
            this.loaded()
          })
        }
      })
      this.datas = []
      this.loadData({ currentPage: 1 })
    },
    refreshData(projectid) {
      this.queryData(projectid).then((_) => {
        this.loaded()
      })
    },
    getProvinceCityList() {
      let param = {
        usercode: this.model.projectmanagercode,
        deptcode: this.model.deptcode
      }
      getAction(this.url.getProvinceCityList, param)
        .then((res) => {
          if (res.success) {
            this.provinceCityList = res.result.provinceCityList
          } else {
            this.$tap.alert(res.message, 'warning')
          }
          this.loading = false
        })
        .catch((err) => {
          this.loading = false
        })
    },
    /** 执行查询 */
    doQuery() {
      this.loadData({ currentPage: 1 })
    },
    /** 获取查询参数 */
    getQueryParams() {
      let param = {
        qry_sourcetype: 'MpmProject',
        qry_sourceid: 0
      }
      if (!this.isAdd) {
        param.qry_sourceid = this.projectId
      }
      Object.assign(param, this.sorterInfo)
      param.currentPage = this.pageInfo.currentPage
      param.pageSize = this.pageInfo.pageSize
      return param
    },
    /** 表格列排序 */
    doSortChange(columnInfo, prop, order) {
      if (columnInfo.column === null) {
        return
      }
      // 不排序
      if (validateNull(columnInfo.order)) {
        this.loadData({})
        return
      }
      // 升序或者降序排序
      if (columnInfo.column.sortBy) {
        this.sorterInfo.sidx = columnInfo.column.sortBy
      } else {
        this.sorterInfo.sidx = columnInfo.prop
      }
      this.sorterInfo.sord = columnInfo.order.replace('ending', '')
      this.loadData({})
    },
    /** 每页大小改变 */
    doChangeSize(val) {
      if (this.pageInfo.pageSize !== val) {
        this.pageInfo.pageSize = val
        this.pageInfo.currentPage = 1
        this.loadData({})
      }
    },
    /** 页面跳转 */
    doChangeIndex(val) {
      if (this.pageInfo.currentPage !== val) {
        this.pageInfo.currentPage = val
        this.loadData({})
      }
    },
    /** 每页大小改变 */
    doChangeSize2(val) {
      if (this.changeInfo.pageInfo.pageSize !== val) {
        this.changeInfo.pageInfo.pageSize = val
        this.changeInfo.pageInfo.currentPage = 1
        this.loadData({})
      }
    },
    /** 页面跳转 */
    doChangeIndex2(val) {
      if (this.changeInfo.pageInfo.currentPage !== val) {
        this.changeInfo.pageInfo.currentPage = val
        this.loadData({})
      }
    },
    /** 每页大小改变 */
    doChangeSize3(val) {
      if (this.circulateInfo.pageInfo.pageSize !== val) {
        this.circulateInfo.pageInfo.pageSize = val
        this.circulateInfo.pageInfo.currentPage = 1
        this.queryCirculateHistory()
      }
    },
    /** 页面跳转 */
    doChangeIndex3(val) {
      if (this.circulateInfo.pageInfo.currentPage !== val) {
        this.circulateInfo.pageInfo.currentPage = val
        this.queryCirculateHistory()
      }
    },
    /** 打开传阅反馈编辑页 **/
    openCirculateDialog() {
      getAction(this.url.ifReviewed, { projectcode: this.projectinfo.projectcode })
        .then((res) => {
          if (res.success) {
            if (res.result) {
              this.$tap.alert('该项目已提交复盘审批，无法新增单据!')
            } else {
              // 判断当前项目是否有传阅反馈记录
              if (this.model.projectcode) {
                getAction(this.url.checkCirculatedRecord, { code: this.model.projectcode })
                  .then((res) => {
                    if (res.success) {
                      // 如果当前用户是项目经理才可编辑，如果来自于归档模块则之恶能查看
                      if (this.model.projectmanagercode !== this.$store.getters.user.code || this.fromIndexType === 'file') {
                        if (res.result.hasrecord) {
                          this.openViewDialog('projectCirculated', res.result.circulatedrecord.id)
                        } else {
                          this.$tap.alert('该项目暂时没有传阅反馈记录', 'warning')
                        }
                      } else {
                        if (res.result.hasrecord) {
                          this.openEditDialog('projectCirculated', res.result.circulatedrecord.id)
                        } else {
                          this.openAddDialog('projectCirculated', this.model)
                        }
                      }
                    } else {
                      this.$tap.alert(res.message, 'warning')
                    }
                  })
                  .catch((err) => {})
              }
            }
          } else {
            this.$tap.alert(res.message, 'warning')
          }
        })
        .catch((err) => {
          this.$tap.alert(err, 'warninig')
        })
    },
    beforeOpenAddDialog(editForm, rowData) {
      this.$refs[editForm].projectModel = rowData
      return true
    },
    queryData(id) {
      this.existschangehistory()
      if (!this.url.load) {
        this.$tap.alert('请设置load地址!', 'warning')
        return
      }
      return getAction(this.url.load, { id: id }).then((res) => {
        if (res.success) {
          this.model = res.result
        } else {
          this.$tap.alert(res.message, 'warning')
        }
      })
    },
    existschangehistory() {
      getAction('/mpm/projectChange/list', { qry_projectcode: this.projectinfo.projectcode, sidx: 'createon', sord: 'desc', pageSize: 10, currentPage: 1 }).then((res) => {
        if (res.success) {
          this.disableChangeHistory = res.result.dataList.length === 0
          if (res.result.dataList.length > 0) {
            this.changehistorymodelid = res.result.dataList[0].id
          }
        } else {
          this.$tap.alert(res.message, 'warning')
        }
      })
    },
    // 数据库字符串对象去特殊字符
    loaded() {
      this.getProvinceCityList()
      // this.$refs.projectBidDate.isAdd = false
      // this.$refs.projectBidDate.disableEditSubmit = true
      // this.$refs.projectBidDate.disableSave = true
      // this.$refs.projectBidDate.open()
      // 客户决策子表加载
      // this.$refs.projectCustomer.isAdd = false
      // this.$refs.projectCustomer.disableEditSubmit = true
      // this.$refs.projectCustomer.disableSave = true
      // this.$refs.projectCustomer.open()
      // 通过项目级别编码为项目级别显示值赋值
      if (this.model.projectlevel && !this.model.projectdefaultlevel && this.codeModel.projectlevelList) {
        let tempLevelData = this.codeModel.projectlevelList.find((item) => item.code === this.model.projectlevel)
        // 若项目默认级别为空则为tempprojectlevel和tempdispprojectlevel赋值
        this.tempprojectlevel = this.model.projectlevel
        this.tempdispprojectlevel = tempLevelData.name
      }
      // 通过项目默认等级为tempprojectlevel和tempdispprojectlevel赋值
      if ((this.model.projectdefaultlevel || this.model.projectdefaultlevel === '0') && this.codeModel) {
        let tempDefaulLevelData = this.codeModel.projectlevelList.find((item) => item.code === this.model.projectdefaultlevel)
        this.tempprojectlevel = this.model.projectdefaultlevel
        this.tempdispprojectlevel = tempDefaulLevelData.name
      }
      // 给midChangePoint赋初始值
      if (this.model.chanceclue) {
        this.midChangePoint = this.model.chanceclue.split(',') <= 1
      }
      this.deptname = []
      if (this.model.deptname1) {
        this.deptname.push(this.model.deptname1)
      }
      if (this.model.deptname2) {
        this.deptname.push(this.model.deptname2)
      }
      if (this.model.deptname3) {
        this.deptname.push(this.model.deptname3)
      }
    },
    /** 修改项目来源时将机会点/线索编号、项目名称、项目金额、默认等级、级别调整原因和其他中间变量清空 **/
    changeSource(select) {
      this.$set(this.model, 'chanceclue', '')
      this.$set(this.model, 'projectname', '')
      this.$set(this.model, 'participatemoney', '')
      this.$set(this.model, 'projectdefaultlevel', '')
      this.$set(this.model, 'changelevelreason', '')
      this.$set(this.model, 'projectlevel', '')
      this.$set(this.model, 'productlist', [])
      this.$set(this.model, 'productoutlist', [])
      this.tempprojectlevel = ''
      this.tempdispprojectlevel = ''
    },
    /** 打开机会点参照 */
    openChanceclueDialog() {
      if (!this.model.projectsource) {
        this.$tap.alert('请先选择项目来源！', 'warning')
      } else {
        this.$refs.changeRef.visible = true
      }
    },
    /** 打开调整项目级别的弹框 **/
    openChangeLevelDialog() {
      this.$refs.changeLevelRef.projectlevelList = this.codeModel.projectlevelList
      this.$refs.changeLevelRef.dispprojectdefaultlevel = this.tempdispprojectlevel
      this.$set(this.$refs.changeLevelRef.model, 'projectlevel', this.model.projectlevel)
      this.$set(this.$refs.changeLevelRef.model, 'dispprojectlevel', this.codeModel.projectlevelList.find((item) => item.code === this.model.projectlevel).name)
      this.$set(this.$refs.changeLevelRef.model, 'changelevelreason', this.model.changelevelreason)
      this.$refs.changeLevelRef.visible = true
    },
    /** 获取项目等级，例网级、省级 **/
    getMaxLevel() {
      let param = {
        currentPage: 1,
        pageSize: 500,
        projectsource: this.model.projectsource,
        sidx: 'sortcode',
        sord: 'asc',
        usercode: this.user.code
      }
      if (this.model.chanceclue) {
        getAction(this.url.changeList, param).then((res) => {
          if (res.success) {
            // 当前用户已选择的线索/机会点
            let codes = this.model.chanceclue.split(',')
            // 当前用户所有的线索/机会点
            res.result.dataList.forEach((item) => {
              if (codes.find((code) => code === item.CODE)) {
                // 取客户等级最大的作为项目等级
                this.maxLevel = Math.max(this.maxLevel, Number(item.CLIENT_LEVEL))
              }
            })
          } else {
            this.$tap.alert('获取线索/机会点列表错误，请联系管理员')
          }
        })
      }
    },
    isCFO() {
      const param = {
        projectId: this.projectId,
        usercode: this.user.code
      }
      getAction(this.url.isCFO, param).then((res) => {
        if (res.success) {
          if (res.result) {
            this.isCFOForThisProject = true
          }
        } else {
          this.$tap.alert('用户职位未获取成功，请联系管理员')
        }
      })
    },
    openChangeManager() {
      const param = {
        projectcode: this.model.projectcode
      }
      getAction(this.url.getProjectChangeManager, param).then((res) => {
        if (res.success) {
          if (res.result && res.result.length > 0) {
            if (res.result[0].state === 0 || res.result[0].state === 2) {
              this.openEditDialog('projectChangeManager', res.result[0].id)
            } else {
              this.openViewDialog('projectChangeManager', res.result[0].id)
            }
          } else {
            this.openAddDialog('projectChangeManager', this.model)
          }
        } else {
          this.$tap.alert('项目经理变更数据未获取成功，请联系管理员')
        }
      })
    },
    changeDeptname() {
      this.model.deptname1 = this.deptname[0]
      this.model.deptname2 = this.deptname[1] || null
      this.model.deptname3 = this.deptname[2] || null
    },
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0 || columnIndex === 2 || columnIndex === 3 || columnIndex === 4) {
        const _row = this.spanArr[rowIndex]
        const _col = _row > 0 ? 1 : 0
        return {
          rowspan: _row,
          colspan: _col
        }
      }
    }
  },
  mounted() {
    this.queryData(this.projectId).then((_) => {
      // 获取项目等级
      this.getMaxLevel()
      this.loaded()
    })
    this.loadData({ currentPage: 1 })
  },
  created() {
    // 判断是否为省区财经副总
    this.isCFO()
  }
}
</script>
<style lang="scss" scoped>
/deep/ .el-collapse-item__header {
  font-size: 18px !important;
  font-weight: bold;
}
/deep/ .el-tabs--border-card {
  box-shadow: 0 0;
  -webkit-box-shadow: 0 0;
}
.secondTabs {
  padding-top: 5px;
  padding-bottom: 6px;
  /deep/ .el-tabs__item {
    height: 30px;
    line-height: 30px;
  }
  /deep/ .el-tabs__nav-wrap::after {
    display: none;
  }
  /deep/ .el-tabs__active-bar {
    height: 1px;
  }
}
/** 表格样式相关 */
.tl-table {
  /** “暂无数据”居中显示 */
  /deep/ .el-table__empty-block {
    justify-content: center;
    align-items: center;
    padding: 0;
  }
  /deep/ .el-table__empty-text {
    text-align: center;
  }
  // 控制边框
  /deep/ .gutter {
    display: none !important;
  }
}
</style>
